from rest_framework.generics import GenericAPIView
from rest_framework.response import Response

from booktest.models import BookInfo
from booktest.serializers import BookInfoSerializer


class  BookDetailView(GenericAPIView):
    queryset = BookInfo.objects.all()
    serializer_class = BookInfoSerializer
    lookup_field = 'btitle'
    lookup_url_kwarg = 'title'
    def get(self,request,title):
        """
        根据书名获取指定的图书:
        1. 根据btitle查询指定的图书
        2. 将图书对象序列化并返回
        """
        book = self.get_object()
        serializer = self.get_serializer(book)
        return Response(serializer.data)